package com.example.springbootsfzy.controller.sunkaixuan;

import com.example.springbootsfzy.domain.Notifications;
import com.example.springbootsfzy.service.sunkaixuan.NotificationsService;
import com.example.springbootsfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("notifications")
@CrossOrigin
public class NotificationsController {

    @Autowired
    private NotificationsService notificationsService;
    

    /*
    * 通过memberid查找
    * */
    @GetMapping("/findbynotificationId/{id}")
    @ResponseBody
    public R findbynotificationId(@PathVariable int id) {
        return R.ok(notificationsService.findbynotificationId(id));
    }
    
    @GetMapping("/selectByPrimaryKey/{id}")
    @ResponseBody
    public R selectByPrimaryKey(@PathVariable int id) {
        return R.ok(notificationsService.selectByPrimaryKey(id));
    }
    
    @PostMapping
    @ResponseBody
    public R insertSelective(@RequestBody Notifications notifications) {
        int i = notificationsService.insertSelective(notifications);
        if (i > 0) {
            return R.ok("添加成功");
        }else {
            return R.error("添加失败");
        }
        
    }
    
    
    @DeleteMapping
    @ResponseBody
    public R deleteByPrimaryKey(@PathVariable int id){
        int i = notificationsService.deleteByPrimaryKey(id);
        if (i > 0) {
            return R.ok("删除成功");
        }else {
            return R.error("删除失败");
        }
    }
    
    @PutMapping
    @ResponseBody
    public R updateByPrimaryKeySelective(@RequestBody Notifications notifications) {
        int i = notificationsService.updateByPrimaryKeySelective(notifications);
        if (i > 0) {
            return R.ok("修改成功");
        }else {
            return R.error("修改失败");
        }
    }


}
